﻿using System;
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using Quartz;
using Quartz.Spi;
using Quartz.Impl;
using Caramel.Quartz.Spi;

namespace Caramel.Quartz.Castle
{
	public class QuartzInstaller : IWindsorInstaller
	{
		public void Install(IWindsorContainer container, IConfigurationStore store)
		{
			container.
				Register(
					Component.
						For<IJobFactory>().
						ImplementedBy<ServiceLocatorJobFactory>().
						LifeStyle.
						Singleton,
					Component.
						For<IScheduler>().
						UsingFactoryMethod(
							k =>
							{
								var scheduler = new StdSchedulerFactory().GetScheduler();
								scheduler.JobFactory = k.Resolve<IJobFactory>();

								return scheduler;
							}
						).
						LifeStyle.
						Singleton
				);
		}
	}
}
